/**
 * @class   wosh::SessionProtocol
 * @brief   The class provides processing of input commands (by the user) and
 *          responses (by the system).
 *
 *
 * Input format is very similar to POSIX shell: \b command/alias \b arguments
 *
 * 
 * You may list internal commands executing \c help (at any location).
 * \verbatim

WOSH Shell Protocol - Commands:
	 help : 	 print this screen
	 man : 	 show manual
	 session : 	 print session info
	 whoami : 	 print username
	 su : 	 switch user
	 echo : 	 reply input
	 proto : 	 change session protocol
	 notify : 	 notify a message to user(s)
	 pwd : 	 print current path
	 ck : 	 change kernel
	 cd : 	 change destination (location)
	 cb : 	 change bus (target)
	 home : 	 change to home URI
	 scd : 	 (smart) change destination (name)
	 which : 	 find method
	 . : 	 repeat last command-line
	 exit : 	 close session

\endverbatim
 *
 * You may repeat last command executing \b .
 *
 * When no arguments are provided content of the generated wosh::Request is set to NULL.
 *
 * A single (simple) argument is interpreted as wosh::Variant and parsed through wosh::Variant::fromString(). Examples:
 * \verbatim
enqueue %MUSIC/IT/Zucchero
play# INT(34)
\endverbatim
 *
 * Multiple arguments are considered as a wosh::List of wosh::Variant (pointers),
 * tokens are splitted evaluating quotes (first) and spaces.
  * \verbatim
enqueue %MUSIC/ST/Deep Purple
\endverbatim
 * is interpreted as List{ Variant[%MUSIC/ST/Deep], Variant[Purple] }, but
  * \verbatim
enqueue "%MUSIC/ST/Deep Purple"
\endverbatim
 * is intepreted as a single argument and represented as wosh::Variant (of type STRING).
 *
 * There is one more feature provided by the current input model, which is inspired to
 * GNU and POSIX software, you may pass specific arguments as field=value using \b -- \c prefix. Example:
  * \verbatim
list --index-start=5 --index-end=8 --fields=all
\endverbatim
 * This dataline will generate a wosh::Table of 3 rows (two columns).
 * Arguments (values, in this case {5,8,'all'}) are stored as wosh::Variant in the
 * second column, fields ('index-start', ..) are stored as Variant in the first column.
 *
 *
 *
 *
 *
 * @see     wosh::communication::ShellCommand for data parsing specifications.
 * @see     wosh::persistence::EncoderWriterPlainText for data rendering information.
 * @see     wosh::SessionManager
 ****************************************************************************
 * @version 0.8.384 $Id: SessionProtocol.h 2634 2010-06-09 23:01:02Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Core_SessionProtocol_H__
 #define __WOSH_Core_SessionProtocol_H__

 #include <woshDefs.h>
 #include <core/Reflection.h>


namespace wosh {

class Session;
class Message;
class Bus;
template <class T> class DataFieldCollector;

class SessionProtocol : public virtual IReflection
 {
	WOSH_CLASSNAME(wosh::SessionProtocol)
	WOSH_CLASS_ABSTRACT(true)

	public:
		SessionProtocol() { }
		virtual ~SessionProtocol() { }

	public:
		static DataFieldCollector<SessionProtocol>* getDataFields();

	public:
		virtual std::string buildPrompt( Session* session ) const = 0;

		virtual WRESULT parseInput( const std::string& dataline, Session* source_session ) = 0;

		virtual WRESULT renderMessage( const Message* message, const Bus* source, Session* source_session ) = 0;

	protected:
		WRESULT postMessage( Message* message, Session* source_session );

		void printMessage( Session* session, const std::string& message );

	protected:
		friend class Session;


}; // class def

}; // namespace wosh

#endif //__WOSH_Core_SessionProtocol_H__
